﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<IEnumerable<MvcProject.Models.MaterialUseRecord>>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    班组成本核算
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <h2>
        班组成本核算</h2>
    <% using (Html.BeginForm())
       {%>
    <%: Html.ValidationSummary(true) %>
    <%: Html.Label(ViewData["projectName"] as string)%>
    <%: Html.Label(ViewData["teamName"] as string)%>
    成本调整：<%: Html.TextBox("txtAdjustment", "100", new { @onkeyup = @"value=value.replace(/[^\d\.\-]/g,'')", @onbeforepaste = @"clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d\.\-]/g,''))" })%>%
    <fieldset>
        <legend>成本核算信息</legend>
        <table id="table_calc">
            <tr>
                <th>
                    选择
                </th>
                <th>
                    定额名称
                </th>
                <th>
                    工程量
                </th>
                <th>
                    人工费
                </th>
                <th>
                    材料费
                </th>
                <th>
                    机械费
                </th>
                <th>
                    管理费
                </th>
                <th>
                    利润
                </th>
                <th>
                    单价
                </th>
                <th>
                    总价
                </th>
            </tr>
            <% foreach (var item in Model)
               { %>
            <tr>
                <td>
                    <input type="checkbox" name="chk" value="<%: item.id %>" />
                </td>
                <td>
                    <%: item.RatedName %>
                </td>
                <td>
                    <%: String.Format("{0:F}", item.Project_volume) %>
                </td>
                <td>
                    <%: String.Format("{0:F}", item.Labor_costs) %>
                </td>
                <td>
                    <%: String.Format("{0:F}", item.Materials_costs) %>
                </td>
                <td>
                    <%: String.Format("{0:F}", item.Machinery_costs) %>
                </td>
                <td>
                    <%: String.Format("{0:F}", item.Management_Fee) %>
                </td>
                <td>
                    <%: String.Format("{0:F}", item.Profit) %>
                </td>
                <td>
                    <%: String.Format("{0:F}", (item.Single_costs))%>
                </td>
                <td>
                    <%: String.Format("{0:F}", item.Project_volume * (item.Single_costs))%>
                </td>
            </tr>
            <% } %>
        </table>
    </fieldset>
    <div>
        <%: Html.DropDownList("teamId", ViewData["teams"] as SelectList, "---选择班组---")%>
        <input type="button" value="保存选择的定额名称到班组" id="btnSaveRatedToGroup"/>
    </div>
    <div>
        <%: Html.ActionLink("返回列表", "../ContractInfo/ProjectContractIndex")%>
    </div>
    <% } %>
    <script type="text/javascript">
        $(function () {
            $('#btnSaveRatedToGroup').click(function () {
                var teamId = $('#teamId').val();
                if (teamId == '') {
                    alert('选择班组');
                    return;
                }
                var txtAdjustment = $('#txtAdjustment').val();
                var str = '';

                $('#table_calc :checkbox[checked]').each(function () {
                    str += $(this).val() + ",";
                });
                if (str == '') {
                    alert('选择定额记录');
                    return;
                }
                str = str.substring(0, str.length - 1);
                $.ajax({
                    type: "POST",
                    contentType: "application/json",
                    url: "../Services/FormCheck.asmx/SaveRatedInfosToGroup",
                    data: "{ratedInfos:'" + str + "', adjustment:'" + txtAdjustment + "', teamId:'" + teamId + "'}",
                    dataType: "json",
                    success: function (result) {
                        if (result.d) {
                            $('#table_calc :checkbox[checked]').each(function () {
                                $(this).parent().parent().remove();
                            });
                        }
                    },
                    error: function (result) {
                        alert(result.responseText);
                    }
                });
            });
        });
    </script>
</asp:Content>
